package edu.bbu.commonproject.desktop.gui.view.swing.utils;

import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;

/**
 * The tray class.
 */
public class Tray extends TrayIcon
{
	/** It initializes the GUEST_POPUP_MENU. */
	public static final int GUEST_POPUP_MENU = 0;
	
	/** It initializes the USER_POPUP_MENU. */
	public static final int USER_POPUP_MENU = 1;
	
	/** The user popup menu. */
	private PopupMenu userPopupMenu;
	
	/** The guest popup menu. */
	private PopupMenu guestPopupMenu;
	
	/** The login item. */
	private MenuItem loginItem;
	
	/** The register item. */
	private MenuItem registerItem;
	
	/** The forgot item. */
	private MenuItem forgotItem;
	
	/** The forogt item. */
	private MenuItem logouItem;
	
	/** The synchronize item. */
	private MenuItem syncItem;
	
	/** The synchronize setup. */
	private MenuItem syncSetups;
	
	/** The privacy setup. */
	private MenuItem privacySetups;
	
	/** The guest help item. */
	private MenuItem guestHelpItem;
	
	/** The guest about item. */
	private MenuItem guestAboutItem;
	
	/** The guest exit item. */
	private MenuItem guestExitItem;
	
	/** The user help item. */
	private MenuItem userHelpItem;
	
	/** the user about item. */
	private MenuItem userAboutItem;
	
	/** The user exit item. */
	private MenuItem userExitItem;
	
	/**
	 * The constructor.
	 */
	public Tray()
	{		
		super(Design.BASE_ICON, "MongoDB file - share");
		
		if(SystemTray.isSupported())
		{
			SystemTray tray = SystemTray.getSystemTray();
			
			userPopupMenu = new PopupMenu();
			guestPopupMenu = new PopupMenu();
			
			loginItem = new MenuItem("Login");
			registerItem = new MenuItem("Register");
			forgotItem = new MenuItem("Forgot password");
			
			syncItem = new MenuItem("Start sync");
			logouItem = new MenuItem("Logout");
			syncSetups = new MenuItem("Sync setups");
			privacySetups = new MenuItem("Privacy setups");
			
			guestHelpItem = new MenuItem("Help");
			guestAboutItem = new MenuItem("About");
			guestExitItem = new MenuItem("Exit");
			
			userHelpItem = new MenuItem("Help");
			userAboutItem = new MenuItem("About");
			userExitItem = new MenuItem("Exit");
			
			guestPopupMenu.add(loginItem);
			guestPopupMenu.add(registerItem);
			guestPopupMenu.add(forgotItem);
			guestPopupMenu.addSeparator();
			guestPopupMenu.add(guestHelpItem);
			guestPopupMenu.add(guestAboutItem);
			guestPopupMenu.addSeparator();
			guestPopupMenu.add(guestExitItem);
			
			userPopupMenu.add(syncItem);
			userPopupMenu.addSeparator();
			userPopupMenu.add(syncSetups);
			userPopupMenu.add(privacySetups);
			userPopupMenu.addSeparator();
			userPopupMenu.add(logouItem);
			userPopupMenu.addSeparator();
			userPopupMenu.add(userHelpItem);
			userPopupMenu.add(userAboutItem);
			userPopupMenu.addSeparator();
			userPopupMenu.add(userExitItem);			
			
			setPopUpMenuType(GUEST_POPUP_MENU);

			this.setImageAutoSize(true);
			
			try
			{
				tray.add(this);
			}
			catch (Exception e){ }
		}
	}
	
	/**
	 * Set the popup menu type.
	 * @param popUpMenuType the popup menu type.
	 */
	public void setPopUpMenuType(int popUpMenuType)
	{
		if(popUpMenuType == USER_POPUP_MENU)
		{
			this.setPopupMenu(userPopupMenu);
		}
		else
		{
			this.setPopupMenu(guestPopupMenu);
		}
	}
	
	/**
	 * Return the status of tray.
	 * @return the status of tray suppoerted.
	 */
	public boolean isTraySupprted()
	{
		return SystemTray.isSupported();
	}
	
	/**
	 * Gets the login item.
	 * @return the login item.
	 */
	public MenuItem getLoginItem()
	{
		return loginItem;
	}
	
	/**
	 * Gets the register item.
	 * @return the register item.
	 */
	public MenuItem getRegisterItem()
	{
		return registerItem;
	}

	/**
	 * Gets the forgoton item.
	 * @return the forgoton item.
	 */
	public MenuItem getForgotItem()
	{
		return forgotItem;
	}
	
	/**
	 * Gets the logout item.
	 * @return the logout item.
	 */
	public MenuItem getLogouItem()
	{
		return logouItem;
	}
	
	/**
	 * Gets the synchronized item.
	 * @return the synchronized item.
	 */
	public MenuItem getSyncItem()
	{
		return syncItem;
	}
	
	/**
	 * Gets the synchronized setup.
	 * @return the synchronized setup.
	 */
	public MenuItem getSyncSetups()
	{
		return syncSetups;
	}
	
	/**
	 * Gets the privacy setup.
	 * @return the privacy setup.
	 */ 
	public MenuItem getPrivacySetups()
	{
		return privacySetups;
	}
	
	/**
	 * Gets the guest help item.
	 * @return the guest help item.
	 */
	public MenuItem getGuestHelpItem()
	{
		return guestHelpItem;
	}
	
	/**
	 * Gets the guest about item.
	 * @return the guest about item.
	 */
	public MenuItem getGuestAboutItem()
	{
		return guestAboutItem;
	}
	
	/**
	 * Gets the guest exit item.
	 * @return the guest exit item.
	 */
	public MenuItem getGuestExitItem()
	{
		return guestExitItem;
	}
	
	/**
	 * Gets the user help item.
	 * @return the user help item.
	 */
	public MenuItem getUserHelpItem()
	{
		return userHelpItem;
	}
	
	/**
	 * Gets the user about item.
	 * @return the user about item.
	 */
	public MenuItem getUserAboutItem()
	{
		return userAboutItem;
	}
	
	/**
	 * Gets the user exit item.
	 * @return the user exit item.
	 */
	public MenuItem getUserExitItem()
	{
		return userExitItem;
	}
}
